#include "nce_servant.h"

namespace nce
{

Servant::Servant(string servName, int port)
{
    _servName = servName;
    _server   = new ServerSocket(port);
}

Servant::~Servant()
{
    delete _server;
}

int Servant::start()
{
    return _server->start(this);
}

int Servant::doServ()
{
	InputBuffer ib;
	OutputBuffer ob;
    string servName;
	
	_server->recv(ib);	// need check return value
	
    // check the servant name
	ib.read(servName);
	if (servName != _servName)
		return -1;
		
	process(ib, ob); 	// need check return value
	
	_server->send(ob); 	// need check return value
	
	return 0;
}

}
